package job

import (
	"sync"
	"workflow/config"
	"workflow/logger"
	"workflow/service"
)

func WorkflowDaemon(done chan int, wg *sync.WaitGroup) {
	logger.Logger.Println("开始监听工作流")
	for {
		select {
		case id := <-config.TriggerChannel:
			logger.Logger.Printf("启动工作流 %s\n", id)
			go service.RunWorkflow(id)
		case <-done:
			wg.Done()
			logger.Logger.Println("工作流线程收到退出信号，安全退出")
			return
		}
	}
}
